import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        PersonSortable[] stu = new PersonSortable[n];
        for(int i=0;i<n;i++)
        {
            String s = cin.next();
            int j = cin.nextInt();
            stu[i]=new PersonSortable(s,j);
        }
        Arrays.sort(stu);
        for(int i=0;i<n;i++)
        {
            System.out.println(stu[i].toString());
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
    }
}
class PersonSortable implements Comparable<PersonSortable> { //comparable类型为PersonSortable类型的
    String name;
    private int age;
    public PersonSortable() {
        this.name = name;
        this.age = age;
    }
    public PersonSortable(String name,int age)
    {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public int compareTo(PersonSortable peo){
        if(this.name.compareTo(peo.name)>0)return 1; //若为升序，则返回1(真)
        else if(this.name.compareTo(peo.name)<0)return -1; //反之返回-1
        else{
            if(this.age<stu.age)return -1;	//若年龄比比较者小，返回-1(假)
            else return 1;				//反之返回1
        }
    }
    @Override
    public String toString()
    {
        return name+"-"+age;
    }
}